<template>
    <div>
        <Modal v-model="modal" class="modal-center" title="添加实体" width=400>
            <div v-if="modalShow" class="form-input">
                <Row class="form-field">
                    <Col class="field-label" span="4">
                    <label>实体</label>
                    </Col>
                    <Col class="field-input" span="20">
                    <Selector ref="entity" v-model="entityId" :path="path.entity"></Selector>
                    </Col>
                </Row>
            </div>
            <div slot="footer" class="button-panel-button">
                <i-button @click="close">取消</i-button>
                <i-button :disabled="!entityId" @click="doActionSubmit" type="primary">确认</i-button>
            </div>
        </Modal>
    </div>
</template>

<script>
import ModalBase from '../modalBase'
import Selector from '@/components/selector'
import $ from '@/common'
export default {
    extends: ModalBase,
    props: {},
    data() {
        return {
            path: {
                entity: '/service/{app}/bill/data/entity/list',
                fields: '/service/{app}/bill/data/entity?id={id}',
                //fields: 'service/{app}/bill/model/{code}?enable_invisible=false'
            },
            datasourceId: null,
            dsCode: null,
            fieldsData: {
                table_cat: null,
                fields: []
            },
            excField: {
                rid: true,
                id: true,
                account_crt_id: true,
                tenantry_id: true,
                crt_ts: true,
                lm_ts: true
            },
            entityId: null
        }
    },
    computed: {},
    methods: {
        load() {
            this.fieldsData = {
                fields: []
            }
        },
        doActionSubmit() {
            //this.fieldsData = this.$refs.entity.selectedData

            $.link(this.path.fields, null, {
                param: {
                    //code: this.$refs.entity.selectedData.code
                    id: this.entityId
                }
            }).then((res) => {
                this.fieldsData.code = res.data.data.code
                this.fieldsData.name = res.data.data.name
                res.data.data.kcs_pf_field.forEach((field) => {
                    if (!this.excField[field.code]) {
                        this.fieldsData.fields.push(field)
                    }
                })
                this.actionSubmit()
            })
        },
        actionSubmit() {
            this.$owner.addRow(this.fieldsData)
            this.close()
        }
    },
    components: {
        Selector
    }
}
</script>

<style lang="less">
.form-input {
    .form-field {
        padding: 8px;
    }
}
</style>
